Conversation
eshaben
left a comment
There was a problem hiding this comment.
thanks for working on this! 🙌
there are some changes I suggested in the deploy contracts test that should also be applied to the send transaction tests. let me know if you have any questions! happy to help! 🙂
| const privateKey = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133' | ||
| const rpcUrl = process.env.HTTP_RPC_ENDPOINT | ||
|
|
||
| async function compile (){ |
There was a problem hiding this comment.
| async function compile (){ | |
| function compile (){ |
| async function compile (){ | ||
| var source = fs.readFileSync('contracts/Incrementer.sol', 'utf8'); | ||
| var input = { | ||
| language: 'Solidity', |
There was a problem hiding this comment.
these indents are 4 spaces, but they should be 2. to fix this and all of the other pages at once, you can run npm run prettier and commit the changes
|
|
||
| async function deployContract(){ | ||
| const account = privateKeyToAccount(privateKey); | ||
| const rpcUrl = process.env.HTTP_RPC_ENDPOINT; |
There was a problem hiding this comment.
the rpcUrl is already defined on line 10, so we don't need it here
| const account = privateKeyToAccount(privateKey); | ||
| const rpcUrl = process.env.HTTP_RPC_ENDPOINT; | ||
| const walletClient = createWalletClient({ | ||
| account, | ||
| chain: moonbeamDev, | ||
| transport: http(rpcUrl), | ||
| }); | ||
| const publicClient = createPublicClient({ | ||
| chain: moonbeamDev, | ||
| transport: http(rpcUrl), | ||
| }); |
There was a problem hiding this comment.
this can be moved outside of the deploy function, so then you don't need to create new variables for these again in the describe functions below
| var contractFile = await compile() | ||
|
|
||
| const bytecode = contractFile.evm.bytecode.object; | ||
| const abi = contractFile.abi; | ||
| const _initialNumber = 5; | ||
|
|
||
| const contract = await walletClient.deployContract({ | ||
| abi, | ||
| account, | ||
| bytecode, | ||
| args: [_initialNumber], | ||
| }); | ||
|
|
||
| var transaction = await publicClient.waitForTransactionReceipt({ | ||
| hash: contract, | ||
| }); | ||
| return transaction.contractAddress | ||
| }; |
There was a problem hiding this comment.
this code doesn't need to be wrapped in the deploy function instead this function can be:
async function deployContract() {
const contractFile = await compile();
const bytecode = contractFile.evm.bytecode.object;
const abi = contractFile.abi;
const _initialNumber = 5;
const contract = await walletClient.deployContract({
abi,
account,
bytecode,
args: [_initialNumber],
});
var transaction = await publicClient.waitForTransactionReceipt({
hash: contract,
});
return transaction.contractAddress;
}
|
|
||
| const fromAddressPrivateKey = "0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133" | ||
| const fromAddress = "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" | ||
| const toAddress = "0x73328873A6Ac3DFc9455986358F5230cB3B8e92c" |
There was a problem hiding this comment.
the toAddress should be randomly generated, i'm not sure exactly how to do that with viem off-hand but I can look into it if you need any help! 🙂
| const fromAddressPrivateKey = "0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133" | ||
| const fromAddress = "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" | ||
| const toAddress = "0x73328873A6Ac3DFc9455986358F5230cB3B8e92c" | ||
| const url = process.env.HTTP_RPC_ENDPOINT |
There was a problem hiding this comment.
these variables just should be moved into the describe fn
| const addressFrom = fromAddress; | ||
| const addressTo = toAddress; |
There was a problem hiding this comment.
these lines shouldn't be necessary, we can just use one name or the other
| }); | ||
| assert.exists(hash); | ||
|
|
||
| // console.log(`Transaction successful with hash: ${hash}`); |
| const addressTo = toAddress; | ||
|
|
||
| const send = async () => { | ||
| // console.log( |
Code refactoring
|
@wuzhong-papermoon - can you go through all of my comments and if you've fixed them, please mark them as resolved, or make the requested changes. And can you also resolve the merge conflicts, please? |
Viem test re-written.